
import br.com.biblioteca.dao.DAOFacade;
import br.com.biblioteca.dao.IBookDAO;
import br.com.biblioteca.dao.ILoanDAO;
import br.com.biblioteca.dao.IUserDAO;
import br.com.biblioteca.vo.Book;
import br.com.biblioteca.vo.Loan;
import br.com.biblioteca.vo.User;
import java.util.Date;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author joaosavio
 */
public class InitDB {
    public static void main(String[] args) {
        putInitialData();
        
       // User user = userDAO.get("test", "test");
     //   System.out.println(user.getLogin());
    }

    public static void putInitialData() {
        IUserDAO userDAO = (IUserDAO) DAOFacade.getDAO(User.class);
        IBookDAO bookDAO = (IBookDAO) DAOFacade.getDAO(Book.class);
        ILoanDAO loanDAO = (ILoanDAO) DAOFacade.getDAO(Loan.class);
        loanDAO.deleteAll();
        userDAO.deleteAll();
        bookDAO.deleteAll();

        User u = new User();
        u.setLastPasswordDateUpdated(new Date());
        u.setLogin("test");
        u.setPassword("test");
        userDAO.add(u);

        for(int i = 0; i < 20; i++) {
            Book b = new Book();
            b.setAutor("teste"+i+1);
            b.setIsbn((i+1)*100);
            b.setTitle("title"+i);
            b.setEditora("publishing"+i);
            b.setDate(new Date());
            b.setBorrowed(0);
            if (i % 2 == 0) {
                b.setArea(Book.Area.biology.toString());
            }
            else {
                b.setArea(Book.Area.english.toString());
            }
            bookDAO.add(b);
        }
    }
}
